﻿@using CleverCMS.Cms.Data.Entities
@model ICollection<CmsMenuItem>

<div class="sidebar-scroll" style="overflow: hidden;" tabindex="5000">
    <div id="sidebar" class="nav-collapse collapse">
        <div class="navbar-inverse">
            <form class="navbar-search visible-phone">
                <input type="text" class="search-query" placeholder="Search">
            </form>
        </div>
        <ul class="sidebar-menu">
            @{ List<CmsMenuItem> childMenu;
               bool isOpen = false;}

            @foreach (var item in Model)
            {
                isOpen = false;
                if (item.ParentId == null)
                {
                    if (ViewBag.OpenMenuID != 0 && item.Id == ViewBag.OpenMenuID)
                    {
                         isOpen= true;
                    }
                    <li class="sub-menu @(isOpen ? "open" : "")">
                        <a href="javascript:;" value=@item.Id>
                            <i class=@String.Concat("icon-",item.Icon ?? "")></i>
                            <span>@item.Title</span>
                            <span class="arrow @(isOpen ? "open" : "")"></span>
                        </a>
                        @{ childMenu = Model.Where(x => x.ParentId == item.Id).OrderBy(m=> m.SortOrder).ToList(); }
                        <ul class="sub" style="display: @( isOpen ? "block" : "none")">
                            @foreach (var menuItem in childMenu)
                            {
                                <li><a href=@menuItem.NavigateUrl>@menuItem.Title</a></li>
                            }
                        </ul>
                    </li>
                }
            }
        </ul>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        $('.sub-menu > a').on('click', function () {
            var id = $(this).attr('value');
            $.cookie('CleverCMS_Menu', id, {path: '/admin', });
        });
    });
</script>
